<?php
class WebConfigAction extends CommonAction {
	public function __construct(){
		parent::__construct();
		
		$this->modelObject = D('WebConfig');
    }
	
    public function index($temp = 'index'){
		$info = $this->modelObject->getWebConfig();
		$this->assign('info', $info);
		
		$this->display($temp);
    }
	
	public function oauth(){
		$this->index('oauth');
	}
	public function email(){
		$this->index('email');
	}
	public function alipay(){
		$this->index('alipay');
	}
	
	public function add(){
		if(IS_POST){
			if($this->modelObject->updateConfig()){
				$this->success('更新成功');	
			}else{
				$this->error('更新失败');	
			}
		}else{
			$this->error('非法操作');	
		}
	}
	
	public function testSendEmail(){
		$testEmail = I('email', '', 'strval');
		if($testEmail){
			if($result = sendMail($testEmail, '测试邮件'.NOW_TIME, '恭喜邮箱配置成功')){
				$this->ajaxReturn(1, '发送成功!', 1);		
			}else{
				$this->ajaxReturn(0, '发送失败!', 0);			
			}
		}else{
			$this->ajaxReturn(0, '请输入接收邮箱!', 0);	
		}
	}
}